class CheckIn {
  int id;
  int app_id;
  int user_id;
  String cycle_start_date;
  String cycle_end_date;
  int checkin_days;
  int makeup_count;
  String? last_checkin_date;
  String updated_at;
  String created_at;
  List<CheckInDetail> details;
  String current_date;

  CheckIn({
    required this.app_id,
    required this.user_id,
    required this.cycle_start_date,
    required this.cycle_end_date,
    required this.checkin_days,
    required this.makeup_count,
    required this.last_checkin_date,
    required this.updated_at,
    required this.created_at,
    required this.id,
    required this.details,
    required this.current_date,
  });

  factory CheckIn.fromJson(Map<String, dynamic> json) {
    return CheckIn(
      app_id: json['app_id'],
      user_id: json['user_id'],
      cycle_start_date: json['cycle_start_date'],
      cycle_end_date: json['cycle_end_date'],
      checkin_days: json['checkin_days'],
      makeup_count: json['makeup_count'],
      last_checkin_date: json['last_checkin_date'],
      updated_at: json['updated_at'],
      created_at: json['created_at'],
      id: json['id'],
      details:
          (json['details'] as List)
              .map((e) => CheckInDetail.fromJson(e))
              .toList(),
      current_date: json['current_date'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'app_id': app_id,
      'user_id': user_id,
      'cycle_start_date': cycle_start_date,
      'cycle_end_date': cycle_end_date,
      'checkin_days': checkin_days,
      'makeup_count': makeup_count,
      'last_checkin_date': last_checkin_date,
      'updated_at': updated_at,
      'created_at': created_at,
      'id': id,
      'details': details.map((e) => e.toJson()).toList(),
      'current_date': current_date,
    };
  }
}

class CheckInDetail {
  int id;
  int checkin_id;
  String checkin_date;
  double hashrate;
  int is_checkin;
  int is_makeup;
  String? checkin_time;
  String created_at;
  String updated_at;

  CheckInDetail({
    required this.id,
    required this.checkin_id,
    required this.checkin_date,
    required this.hashrate,
    required this.is_checkin,
    required this.is_makeup,
    this.checkin_time,
    required this.created_at,
    required this.updated_at,
  });

  factory CheckInDetail.fromJson(Map<String, dynamic> json) {
    return CheckInDetail(
      id: json['id'],
      checkin_id: json['checkin_id'],
      checkin_date: json['checkin_date'],
      hashrate: json['hashrate'].toDouble(),
      is_checkin: json['is_checkin'],
      is_makeup: json['is_makeup'],
      checkin_time: json['checkin_time'] ?? '',
      created_at: json['created_at'],
      updated_at: json['updated_at'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'checkin_id': checkin_id,
      'checkin_date': checkin_date,
      'hashrate': hashrate,
      'is_checkin': is_checkin,
      'is_makeup': is_makeup,
      'checkin_time': checkin_time ?? '',
      'created_at': created_at,
      'updated_at': updated_at,
    };
  }
}
